<?php
namespace app\index\controller;

use app\common\controller\Base;
use app\index\model\LLogin;
use app\index\controller\Server;
use think\Config;
use think\Request;

/**
 * 留存日志
 */
class Devretention extends Base
{

    //use \app\index\controller\traits\CurlRequest;

    protected $model;

    /**
     * 控制器初始化
     * @return   void
     */
    public function _initialize()
    {
        //基类授权
        //
        parent::_initialize();
        $this->llogin = new LLogin();
        $this->model = new \app\index\model\Devretention();

        # 记录开服日期
        # 
        $this->server = new Server();
        $this->new_open_date = $this->server->getOpenDate();
    }

    public function doList(Request $request)
    {

        //输入

        $sid = input('sid/s');
        $channel = input('channel/s');

        $startdate = input('startdate/s');
        $enddate = input('enddate/s');

        $map = [];

        //必选区间
        if (!empty($startdate) && !empty($enddate)) {
            $map = ['date' => array('between', array($startdate, $enddate))];
        } else if (!empty($startdate)) {
            $map = ['date' => array('>=', $startdate)];
        } else if (!empty($enddate)) {
            $map = ['date' => array('<=', $enddate)];
        } else {
            //默认参数配合仓库自动加载
            $enddate = date('Y-m-d');
            $map = ['date' => array('<=', $enddate)];
        }

        //可选统计
        if (!empty($sid)) {
            $map['sid'] = $sid;
        }

        if (!empty($channel)) {
            $map['channel'] = $channel;
        }

        $res = $this->model->doList($map);
        _callback($res);
    }

    public function getOpenDAU()
    {
        $opendate = $this->new_open_date;

        $res = $this->llogin->getDAUByDevice($opendate);
        dump($res);
    }
}
